package qc.module.demo.api.controller;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import qc.common.core.constants.QCAuthConstant;
import qc.common.core.exception.QCPromptException;
import qc.common.core.utils.DateUtil;
import qc.module.demo.dto.weixin.*;
import qc.module.platform.dto.uac.LoginDto;
import qc.module.platform.dto.uac.LoginResultDto;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 微信小程序测试使用
 * 用于测试小程序获取身份信息，元谋智慧水务开发中的微信小程序测试数据提供
 *
 * @author QuCheng Tech
 * @create 2023/1/30
 */
@RestController
@RequestMapping("/weixin")
public class WeixinTestController {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    HttpServletRequest request;

    @GetMapping("/token1")
    public String TestGetToken() {
        //权限验证需要token，获取token
        String token = request.getHeader(QCAuthConstant.TOKEN_HEADER_KEY);

        //根据token获取用户id
        //在platform中使用直接调用，在其他项目中使用微服务之间调用方式

        return token;
    }

    @GetMapping("/service")
    public LoginResultDto TestMicroService() throws QCPromptException {
        //从nacos中获取服务地址
        List<ServiceInstance>  instances = discoveryClient.getInstances("module-platform");
        //如果获取到的微服务的实例数为0，抛出异常提示
        if(instances==null || instances.size()<0x1)
            throw new QCPromptException("调用module-platform微服务时无任何有效的实例。");

        ServiceInstance service = instances.get(0);
        //通过绝对url调用微服务
        //此调用方法会经过网关，gateway中为一次完整的请求记录--不经过gateway没有记录
        //获取指定微服务的host和端口，不会经过gateway
        String url = "http://" + service.getHost() + ":" + service.getPort() + "/uac/login";
        //通过restTemplate调用
        //Goods goods = restTemplate.getForObject("http://" + url + "/goods/getGoods/" + id, Goods.class);
        //传递参数
        LoginDto loginDto = new LoginDto();
        loginDto.setCode("login-uname");
        loginDto.setPwd("login-pwd");
        LoginResultDto resultDto = restTemplate.postForObject(url, loginDto, LoginResultDto.class);

        //这里通过exchange访问  兼容post get put delete等方式
        //ResponseEntity<String> response = restTemplate.exchange(
        //        url,//获取资源的地址
        //        HttpMethod.POST,
        //        formEntity,
        //        String.class//返回类型设为String
        //);

        return resultDto;
    }

    @GetMapping("/test1")
    public List<StationClassifyStatisticsItemDto> statisticsByClassify(@RequestHeader(value = QCAuthConstant.TOKEN_HEADER_KEY, required = false) String token) {
        List<StationClassifyStatisticsItemDto> result = new ArrayList<>();

        StationClassifyStatisticsItemDto itemDto;
        Random random = new Random();
        int num1 = random.nextInt(100);
        int num2 = random.nextInt(100);
        int total = num1 >= num2 ? num1 : num2;
        int normal = num1 >= num2 ? num2 : num1;
        int fault = total - normal;
        float percent = (float) normal / (float) total * 100.0f;

        itemDto = new StationClassifyStatisticsItemDto();
        itemDto.setName("水位站");
        itemDto.setTotal(total);
        itemDto.setNormal(normal);
        itemDto.setFault(fault);
        itemDto.setPercent(percent);
        result.add(itemDto);

        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        fault = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        itemDto = new StationClassifyStatisticsItemDto();
        itemDto.setName("雨量站");
        itemDto.setTotal(total);
        itemDto.setNormal(normal);
        itemDto.setFault(fault);
        itemDto.setPercent(percent);
        result.add(itemDto);

        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        fault = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        itemDto = new StationClassifyStatisticsItemDto();
        itemDto.setName("水库站");
        itemDto.setTotal(total);
        itemDto.setNormal(normal);
        itemDto.setFault(fault);
        itemDto.setPercent(percent);
        result.add(itemDto);

        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        fault = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        itemDto = new StationClassifyStatisticsItemDto();
        itemDto.setName("水质站");
        itemDto.setTotal(total);
        itemDto.setNormal(normal);
        itemDto.setFault(fault);
        itemDto.setPercent(percent);
        result.add(itemDto);


        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        fault = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        itemDto = new StationClassifyStatisticsItemDto();
        itemDto.setName("视频站");
        itemDto.setTotal(total);
        itemDto.setNormal(normal);
        itemDto.setFault(fault);
        itemDto.setPercent(percent);
        result.add(itemDto);

        return result;
    }

    @GetMapping("/latestdata1")
    public List<WaterLatestDataItemDto> getWaterLatestItem(){
        List<WaterLatestDataItemDto> result = new ArrayList<>();

        WaterLatestDataItemDto waterDto;
        Date time = DateUtil.getNowDate();
        String tm = DateUtil.getDateTimeString(time);
        Random random = new Random();
        float water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("上你莫水库");
        waterDto.setDivision("黄瓜园镇");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("弯腰树水库");
        waterDto.setDivision("平田乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("马道地水库");
        waterDto.setDivision("老城乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("新河水库");
        waterDto.setDivision("物茂乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("鼠街水库");
        waterDto.setDivision("新华乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("河尾水库");
        waterDto.setDivision("新华乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        water = 800+random.nextFloat()*100;

        waterDto = new WaterLatestDataItemDto();
        waterDto.setName("丙令水库");
        waterDto.setDivision("平田乡");
        waterDto.setTm(tm);
        waterDto.setWater(water);
        result.add(waterDto);

        return result;
    }

    @GetMapping("/latestdata2")
    public List<RainLatestDataItemDto> getRainLatestItem(){
        List<RainLatestDataItemDto> result = new ArrayList<>();

        RainLatestDataItemDto rainDto;
        Random random = new Random();
        float num1 = random.nextFloat()*20;
        float num2 = random.nextFloat()*20;
        float rain24 = num1 >= num2 ? num1 : num2;
        float rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("河外");
        rainDto.setDivision("物茂乡");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("领庄");
        rainDto.setDivision("黄瓜园镇");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("中村");
        rainDto.setDivision("江边乡");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("大河边");
        rainDto.setDivision("新华乡");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("猛连");
        rainDto.setDivision("新华乡");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        rainDto = new RainLatestDataItemDto();

        rainDto.setName("龙街村委会");
        rainDto.setDivision("江边乡");
        rainDto.setRain(rain);
        rainDto.setRain24(rain24);
        result.add(rainDto);

        return result;
    }

    @GetMapping("/latestdata3")
    public List<ReservoirLatestDataItemDto> getReservoirLatestDataItem(){
        List<ReservoirLatestDataItemDto> result = new ArrayList<>();

        ReservoirLatestDataItemDto reservoirDto;
        Date time = DateUtil.getNowDate();
        String tm = DateUtil.getDateTimeString(time);
        Random random = new Random();
        float water = 800 + random.nextFloat()*100;
        float num1 = random.nextFloat()*20;
        float num2 = random.nextFloat()*20;
        float rain24 = num1 >= num2 ? num1 : num2;
        float rain = num1 >= num2 ? num2 : num1;
        float v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("秧田箐水库");
        reservoirDto.setDivision("元马镇");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        water = 800 + random.nextFloat()*100;
        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("储麦水库");
        reservoirDto.setDivision("老城乡");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        water = 800 + random.nextFloat()*100;
        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("卡莫水库");
        reservoirDto.setDivision("江边乡");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        water = 800 + random.nextFloat()*100;
        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("丙令水库");
        reservoirDto.setDivision("平田乡");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        water = 800 + random.nextFloat()*100;
        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("鼠街水库");
        reservoirDto.setDivision("新华乡");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        water = 800 + random.nextFloat()*100;
        num1 = random.nextFloat()*20;
        num2 = random.nextFloat()*20;
        rain24 = num1 >= num2 ? num1 : num2;
        rain = num1 >= num2 ? num2 : num1;
        v = water * 100;

        reservoirDto = new ReservoirLatestDataItemDto();
        reservoirDto.setName("河尾水库");
        reservoirDto.setDivision("新华乡");
        reservoirDto.setTm(tm);
        reservoirDto.setWater(water);
        reservoirDto.setV(v);
        reservoirDto.setRain(rain);
        reservoirDto.setRain24(rain24);
        result.add(reservoirDto);

        return result;
    }

    @GetMapping("/latestdata4")
    public List<QualityLatestDataItemDto> getQualityLatestDataItem(){
        List<QualityLatestDataItemDto> result = new ArrayList<>();

        QualityLatestDataItemDto qualityDto;
        Random random = new Random();
        int quality = random.nextInt(4)+1;
        int dest = 5;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("丙间水库");
        qualityDto.setDivision("老城乡");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        quality = random.nextInt(4)+1;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("河尾水库");
        qualityDto.setDivision("新华乡");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        quality = random.nextInt(4)+1;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("麻柳水库");
        qualityDto.setDivision("老城乡");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        quality = random.nextInt(4)+1;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("丙巷河水库");
        qualityDto.setDivision("元马镇");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        quality = random.nextInt(4)+1;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("坛罐窑水库");
        qualityDto.setDivision("大姚县");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        quality = random.nextInt(4)+1;

        qualityDto = new QualityLatestDataItemDto();
        qualityDto.setName("卡莫水库");
        qualityDto.setDivision("江边乡");
        qualityDto.setQuality(quality);
        qualityDto.setDest(dest);
        result.add(qualityDto);

        return result;
    }

    @GetMapping("/latestdata5")
    public List<VideoLatestDataItemDto> getVideoLatestDataItem(){
        List<VideoLatestDataItemDto> result = new ArrayList<>();

        VideoLatestDataItemDto videoDto;
        Random random = new Random();
        String ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        String uid ="user_" + RandomStringUtils.randomNumeric(4);
        String pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("河尾水库");
        videoDto.setDivision("新华乡");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        uid ="user_" + RandomStringUtils.randomNumeric(4);
        pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("弯腰树水库");
        videoDto.setDivision("平田乡");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        uid ="user_" + RandomStringUtils.randomNumeric(4);
        pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("丙令水库");
        videoDto.setDivision("平田乡");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        uid ="user_" + RandomStringUtils.randomNumeric(4);
        pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("丙巷河水库");
        videoDto.setDivision("元马镇");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        uid ="user_" + RandomStringUtils.randomNumeric(4);
        pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("丙间水库");
        videoDto.setDivision("老城乡");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        ip = "http://"+random.nextInt(256)+"."+random.nextInt(256)
                +"."+random.nextInt(256)+"."+random.nextInt(256);
        uid ="user_" + RandomStringUtils.randomNumeric(4);
        pwd = RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomNumeric(6);

        videoDto = new VideoLatestDataItemDto();
        videoDto.setName("新河水库");
        videoDto.setDivision("物茂乡");
        videoDto.setIp(ip);
        videoDto.setUid(uid);
        videoDto.setPwd(pwd);
        result.add(videoDto);

        return result;
    }

    @GetMapping("/warningdata1")
    public List<WarningClassifyStatisticsItemDto> getWarningClassifyItem(){
        List<WarningClassifyStatisticsItemDto> result = new ArrayList<>();

        WarningClassifyStatisticsItemDto warningDto;
        Random random = new Random();
        int num1 = random.nextInt(100);
        int num2 = random.nextInt(100);
        int total = num1 >= num2 ? num1 : num2;
        int normal = num1 >= num2 ? num2 : num1;
        int falt = total - normal;
        float percent = (float) normal / (float) total * 100.0f;

        warningDto = new WarningClassifyStatisticsItemDto();
        warningDto.setName("强降雨实时预警");
        warningDto.setTotal(total);
        warningDto.setNormal(normal);
        warningDto.setFault(falt);
        warningDto.setPercent(percent);
        result.add(warningDto);

        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        falt = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        warningDto = new WarningClassifyStatisticsItemDto();
        warningDto.setName("水位超限实时预警");
        warningDto.setTotal(total);
        warningDto.setNormal(normal);
        warningDto.setFault(falt);
        warningDto.setPercent(percent);
        result.add(warningDto);

        num1 = random.nextInt(100);
        num2 = random.nextInt(100);
        total = num1 >= num2 ? num1 : num2;
        normal = num1 >= num2 ? num2 : num1;
        falt = total - normal;
        percent = (float) normal / (float) total * 100.0f;

        warningDto = new WarningClassifyStatisticsItemDto();
        warningDto.setName("大坝安全实时预警");
        warningDto.setTotal(total);
        warningDto.setNormal(normal);
        warningDto.setFault(falt);
        warningDto.setPercent(percent);
        result.add(warningDto);

        return result;
    }

    @GetMapping("/warningdata2")
    public List<WarningGradeStatisticsItemDto> getRainWarningItem(){
        List<WarningGradeStatisticsItemDto> result = new ArrayList<>();

        WarningGradeStatisticsItemDto rainWarningDto;
        Random random = new Random();
        int count = random.nextInt(3) + 60;

        rainWarningDto = new WarningGradeStatisticsItemDto();
        rainWarningDto.setName("无预警");
        rainWarningDto.setLevel(0);
        rainWarningDto.setCount(count);
        result.add(rainWarningDto);

        count = random.nextInt(3);

        rainWarningDto = new WarningGradeStatisticsItemDto();
        rainWarningDto.setName("蓝色");
        rainWarningDto.setLevel(1);
        rainWarningDto.setCount(count);
        result.add(rainWarningDto);

        count = random.nextInt(3);

        rainWarningDto = new WarningGradeStatisticsItemDto();
        rainWarningDto.setName("黄色");
        rainWarningDto.setLevel(2);
        rainWarningDto.setCount(count);
        result.add(rainWarningDto);

        count = random.nextInt(3);

        rainWarningDto = new WarningGradeStatisticsItemDto();
        rainWarningDto.setName("橙色");
        rainWarningDto.setLevel(3);
        rainWarningDto.setCount(count);
        result.add(rainWarningDto);

        count = random.nextInt(3);

        rainWarningDto = new WarningGradeStatisticsItemDto();
        rainWarningDto.setName("红色");
        rainWarningDto.setLevel(4);
        rainWarningDto.setCount(count);
        result.add(rainWarningDto);

        return result;
    }

    @GetMapping("/warningdata3")
    public List<WarningGradeStatisticsItemDto> getWaterWarningItem(){
        List<WarningGradeStatisticsItemDto> result = new ArrayList<>();

        WarningGradeStatisticsItemDto waterWarningDto;
        Random random = new Random();
        int count = random.nextInt(10) + 80;

        waterWarningDto = new WarningGradeStatisticsItemDto();
        waterWarningDto.setName("水位正常");
        waterWarningDto.setLevel(0);
        waterWarningDto.setCount(count);
        result.add(waterWarningDto);

        count = random.nextInt(5);

        waterWarningDto = new WarningGradeStatisticsItemDto();
        waterWarningDto.setName("水位超限");
        waterWarningDto.setLevel(1);
        waterWarningDto.setCount(count);
        result.add(waterWarningDto);

        count = random.nextInt(5);

        waterWarningDto = new WarningGradeStatisticsItemDto();
        waterWarningDto.setName("低于正常蓄水位");
        waterWarningDto.setLevel(2);
        waterWarningDto.setCount(count);
        result.add(waterWarningDto);

        return result;
    }

    @GetMapping("/warningdata4")
    public List<WarningGradeStatisticsItemDto> getDamWanringItem(){
        List<WarningGradeStatisticsItemDto> result = new ArrayList<>();

        WarningGradeStatisticsItemDto damWarningDto;
        Random random = new Random();
        int count = random.nextInt(10) + 80;

        damWarningDto = new WarningGradeStatisticsItemDto();
        damWarningDto.setName("无安全隐患");
        damWarningDto.setLevel(0);
        damWarningDto.setCount(count);
        result.add(damWarningDto);

        count = random.nextInt(5);

        damWarningDto = new WarningGradeStatisticsItemDto();
        damWarningDto.setName("有安全隐患");
        damWarningDto.setLevel(1);
        damWarningDto.setCount(count);
        result.add(damWarningDto);

        return result;
    }

    @GetMapping("/userbind")
    public BindWeixinUserResultDto getUserBind(@RequestParam(value = "phone" , required = true) String phone){
        BindWeixinUserResultDto userResultDto = new BindWeixinUserResultDto();

        if(StringUtils.isBlank(phone)){
            //未输入号码
            userResultDto.setSuccess(false);
            userResultDto.setToken("");
            userResultDto.setMsg("请输入电话号码！");
        }else {
            Random random = new Random();
            int num = random.nextInt(2);

            if(num == 0){
                //输入号码已存在
                userResultDto.setSuccess(false);
                userResultDto.setToken("");
                userResultDto.setMsg("用户信息已存在！");
            }else {
                //信息绑定成功
                String token = RandomStringUtils.randomAlphabetic(20);

                userResultDto.setSuccess(true);
                userResultDto.setToken(token);
                userResultDto.setMsg("绑定成功");
            }
        }

        return userResultDto;
    }

    @GetMapping("/userinfo")
    public UserInfoDto getUserInfo(){
        UserInfoDto userInfoDto = new UserInfoDto();
        String name = RandomStringUtils.random(1,"张李王赵") + RandomStringUtils.random(1,"一二三四五六");
        String phone = "1" + RandomStringUtils.random(1,"358")+RandomStringUtils.random(1,"1234567890")+
                "****" + RandomStringUtils.randomNumeric(4);

        userInfoDto.setName(name);
        userInfoDto.setPhone(phone);
        userInfoDto.setNotice("您有一条新的巡河任务，点此查看。");

        return userInfoDto;
    }
}
